package com.bootdo.system.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bootdo.system.dao.DlPositionSubclassDao;
import com.bootdo.system.domain.DlPositionSubclassDO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.system.domain.DlPositionDO;
import com.bootdo.system.service.DlPositionService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-06-07 09:22:52
 */
 
@Controller
@RequestMapping("/system/dlPosition")
public class DlPositionController {
	@Autowired
	private DlPositionService dlPositionService;
	@Autowired
	private DlPositionSubclassDao dlPositionSubclassDao;

	@GetMapping()
	@RequiresPermissions("system:dlPosition:dlPosition")
	String DlPosition(){
	    return "system/dlPosition/dlPosition";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:dlPosition:dlPosition")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<DlPositionDO> dlPositionList = dlPositionService.list(query);
		int total = dlPositionService.count(query);
		PageUtils pageUtils = new PageUtils(dlPositionList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:dlPosition:add")
	String add(Model model){
		List<DlPositionSubclassDO> list = dlPositionSubclassDao.list(new HashMap<>());
		model.addAttribute("list", list);
		return "system/dlPosition/add";
	}

	@GetMapping("/edit/{positionId}")
	@RequiresPermissions("system:dlPosition:edit")
	String edit(@PathVariable("positionId") Integer positionId,Model model){
		DlPositionDO dlPosition = dlPositionService.get(positionId);
		List<DlPositionSubclassDO> list = dlPositionSubclassDao.list(new HashMap<>());
		model.addAttribute("list", list);
		model.addAttribute("dlPosition", dlPosition);
	    return "system/dlPosition/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:dlPosition:add")
	public R save( DlPositionDO dlPosition){
		if(dlPositionService.save(dlPosition)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:dlPosition:edit")
	public R update( DlPositionDO dlPosition){
		dlPositionService.update(dlPosition);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:dlPosition:remove")
	public R remove( Integer positionId){
		if(dlPositionService.remove(positionId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:dlPosition:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] positionIds){
		dlPositionService.batchRemove(positionIds);
		return R.ok();
	}
	
}
